package com.cskaoyan.market.controller;

import com.cskaoyan.market.service.WxFeedBackService;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {

    @Autowired
    WxFeedBackService feedBackService;

    //提交反馈意见
    @PostMapping("submit")
    public Object submit(@RequestBody String feedback, HttpSession session) {

        /* MarketUser user = (MarketUser) session.getAttribute("info");
        Integer id = 0;
        if (user != null) {
            id = user.getId();
        }*/
        Integer userId=1;
        String content = JacksonUtil.parseString(feedback, "content");
        String feedType = JacksonUtil.parseString(feedback, "feedType");
        Boolean hasPicture = JacksonUtil.parseBoolean(feedback, "hasPicture");
        String mobile = JacksonUtil.parseString(feedback, "mobile");
        List<String> picUrls = JacksonUtil.parseStringList(feedback, "picUrls");

        String[] newPicUrls = picUrls.toArray(new String[picUrls.size()]);

        int result = feedBackService.submit(content, feedType, hasPicture, mobile, newPicUrls, userId);
        if (result == 200) {

            return ResponseUtil.ok();
        }
        return ResponseUtil.badArgumentValue();
    }

}

